var tgd = tgd || {};
tgd.Utilities = tgd.Utilities || {};
tgd.Utilities.Calendar = tgd.Utilities.Calendar || {};
tgd.Utilities.Calendar.Views = tgd.Utilities.Calendar.Views || {};

tgd.Utilities.Calendar.Views.ASCIIMonth = function (canvas, month) {
	this._canvas = canvas;
	this._month = month;

	var cur = 0;
	var cal = new tgd.Utilities.StringBuilder();

	/* Month and Year */
	cal.append("&nbsp;")
		.append(this._month.getMonthName())
		.repeat("&nbsp;", 22 - this._month.getMonthName().length)
		.append(this._month.getYear())
		.append("&nbsp;")
		.append(" ");

	/* Days of the Week */
	for (var i = 0; i < 7; ++i) {
		cal.append("&nbsp;&nbsp;")
			.append(tgd.Utilities.Calendar.DayNames.getDayAbbreviation(i))
			.append("&nbsp;");
	}

	cal.append(" ");

	for (var i = 0; i < 6; ++i) {  //5 rows in the calendar
		for (var j = 0; j < 7; ++j) {  //7 days per week
			if (cur === 0 && j === this._month.getFirstDayOfWeek()) {
				++cur;
			}
				
			if (cur === 0 || cur > this._month.getNumberOfDaysInMonth()) {
				cal.append("&nbsp;&nbsp;&nbsp;&nbsp;");
			} else {
				cal.append("&nbsp;")
					.append(cur < 10 ? "&nbsp;" : "")
					.append(cur)
					.append("&nbsp;")
				++cur;
			}
		}

		cal.append(" ");
	}

	this._canvas.innerHTML = cal;
}